import DataItemModel from "../../../cfw/mvc/DataItemModel";
import User from "../../db/User";
import { ItemState } from "../../../cfw/tools/Define";


export enum GiftItemModelEnum {
	icon,// 图标
	box,// 对应的箱子
	audio,// 声音文件
	open,
}

/**
* 礼物表
**/
export default class GiftItemModel extends DataItemModel {

	static CLASS_NAME: string = 'GiftItemModel'

	init(id, data) {
		super.init(id, data)
		this.state = User.instance().getGiftState(this.ID)
		if (this.state == ItemState.NOT_GET) {
			if (this.getOpen() == 1) {
				this.setState(ItemState.CAN_GET)
			}
		}
	}

	setState(s: ItemState) {
		super.setState(s)
		User.instance().setGiftState(this.ID, s)
	}

	// 图标
	getIcon() {
		return 'texture/toy/' + this.data[GiftItemModelEnum.icon]
	}
	// 对应的箱子
	getBox() {
		return 'texture/box/' + this.data[GiftItemModelEnum.box]
	}
	// 声音文件
	getAudio() {
		let path = this.data[GiftItemModelEnum.audio]
		if(!path){
			return ''
		}
		return 'audio/gift/' + path
	}

	getOpen() {
		return this.data[GiftItemModelEnum.open]
	}

	isOpen() {
		return this.getOpen() == 1 || this.state == ItemState.CAN_GET;
	}



}